package com.zfsbs.core.action;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.RemoteException;
import android.util.Log;

import com.config.ConstantsConfig;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.model.Couponsn;
import com.model.SbsPrinterData;
import com.model.ShiftRoom;
import com.nld.cloudpos.aidl.printer.AidlPrinterListener;
import com.nld.cloudpos.aidl.printer.PrintItemObj;
import com.nld.cloudpos.data.PrinterConstant;
import com.tool.utils.utils.FyAidlUtils;
import com.tool.utils.utils.LogUtils;
import com.tool.utils.utils.SPUtils;
import com.tool.utils.utils.StringUtils;
import com.tool.utils.utils.ToastUtils;
import com.zfsbs.activity.test.PrintUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class FyPrintUtils {





    /**
     * 打印文本
     */
    public static String printText(Context context, final SbsPrinterData printerData) {


        JSONObject jsonObject = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        try {
            //打印文字
//            jsonArray.put(PrintUtils.setStringContent("交易明细/TXN LIST", 2, 3));
//            jsonArray.put(PrintUtils.setStringContent("凭证号      商户单号      订单金额      交易金额", 1, 1));
//            jsonArray.put(PrintUtils.setStringContent("VOUCHER  ORDER NUMBER    TOTALAMOUNT  SALEAMOUNT", 1, 1));
//            jsonArray.put(PrintUtils.setStringContent("================================================", 1, 1));// 打印虚线
//            for (int i = 0; i < 2; i++) {
//                /*
//                 * 打印交易明细, 1根据ctype判断要打印的内容 1.C1,C2微信查询和支付宝查询不打印交易明细
//                 * 2.D1,D2微信撤销和支付宝撤销加负号,price等于0,两个都用了money 3.
//                 */
//                jsonArray.put(PrintUtils.setStringContent("" + i + " " + "201709061133123456"
//                        + "0.01" + "0.01", 1, 1));
//            }
//            jsonArray.put(PrintUtils.setStringContent("POS签购单", 1, 3));// 打印切纸线
//            jsonArray.put(PrintUtils.setfreeLine("5"));



            switch (printerData.getPayType()){
                case ConstantsConfig.PAY_WAY_RECHARGE_FLOT:
                case ConstantsConfig.PAY_WAY_RECHARGE_ALY:
                case ConstantsConfig.PAY_WAY_RECHARGE_WX: {
                    if (!StringUtils.isBlank(printerData.getRealize_card_num())) {
                        jsonArray.put(PrintUtils.setStringContent("会员卡号：" + StringUtils.formatSTCardNo(printerData.getRealize_card_num()), 1, 2));
                    }
                    if (!StringUtils.isBlank(printerData.getMember_name())) {
                        jsonArray.put(PrintUtils.setStringContent("会员姓名：" + printerData.getMember_name(),1, 2));
                    }
                    if (!StringUtils.isBlank(printerData.getAmount())) {
                        jsonArray.put(PrintUtils.setStringContent("充值金额：" + printerData.getAmount() + "元", 1, 2));
                    }
                    int largessAmount = printerData.getOrderAmount() - StringUtils.stringToInt(printerData.getAmount());
                    if (largessAmount != 0) {
                        jsonArray.put(PrintUtils.setStringContent("充值赠送：" + StringUtils.formatIntMoney(largessAmount) + "元", 1, 2));
                    }
                    if (printerData.getOrderAmount() != 0) {
                        jsonArray.put(PrintUtils.setStringContent("到账金额：" + StringUtils.formatIntMoney(printerData.getOrderAmount()) + "元", 1, 2));
                    }
                    if (printerData.getPacektRemian() != 0) {
                        jsonArray.put(PrintUtils.setStringContent("账号余额：" + StringUtils.formatIntMoney(printerData.getPacektRemian()) + "元", 1, 2));
                    }
                }
                break;
                case ConstantsConfig.PAY_WAY_QB:
                case ConstantsConfig.PAY_WAY_STK:
                    jsonArray.put(PrintUtils.setStringContent("收款凭证", 2, 3));
                    jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));// 打印虚线
                    jsonArray.put(PrintUtils.setfreeLine("5"));
                    jsonArray.put(PrintUtils.setStringContent("商户名称：" + printerData.getMerchantName(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("终端编号：" + printerData.getTerminalId(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("操作员号：" + printerData.getOperatorNo(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("交易类型：" + "钱包", 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("订 单 号：" + printerData.getClientOrderNo(), 1,2));
                    jsonArray.put(PrintUtils.setStringContent("日期时间：" + printerData.getDateTime(), 1,2));
                    jsonArray.put(PrintUtils.setStringContent("金 额：RMB " + printerData.getAmount(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));
                    jsonArray.put(PrintUtils.setfreeLine("2"));

                    if (printerData.getPacektRemian() != 0){
                        jsonArray.put(PrintUtils.setStringContent("会员账号余额：" + StringUtils.formatIntMoney(printerData.getPacektRemian()) + "元", 1, 2));
                    }
                    if (printerData.getPointCoverMoney() != 0) {
                        jsonArray.put(PrintUtils.setStringContent("积分抵扣金额：" + StringUtils.formatIntMoney(printerData.getPointCoverMoney()) + "元", 1, 2));
                    }
                    if (printerData.getCouponCoverMoney() != 0) {
                        jsonArray.put(PrintUtils.setStringContent("优惠券抵扣金额：" + StringUtils.formatIntMoney(printerData.getCouponCoverMoney()) + "元", 1, 2));
                    }
                    if (printerData.getBackAmt() != 0) {
                        jsonArray.put(PrintUtils.setStringContent("返利金额：" + StringUtils.formatIntMoney(printerData.getBackAmt()) + "元", 1, 2));
                    }
                    jsonArray.put(PrintUtils.setfreeLine("2"));
                    break;
                case ConstantsConfig.PAY_WAY_CASH:

                    jsonArray.put(PrintUtils.setStringContent("收款凭证", 2, 3));
                    jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));// 打印虚线
                    jsonArray.put(PrintUtils.setStringContent("商户名称：" + printerData.getMerchantName(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("终端编号：" + printerData.getTerminalId(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("操作员号：" + printerData.getOperatorNo(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("交易类型：" + "现金/CASH", 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("订 单 号：" + printerData.getClientOrderNo(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("日期时间：" + printerData.getDateTime(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("金 额：RMB " + printerData.getReceiveAmount(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));
                    jsonArray.put(PrintUtils.setfreeLine("2"));
                    if (printerData.getPointCoverMoney() != 0) {
                        jsonArray.put(PrintUtils.setStringContent("积分抵扣金额：" + StringUtils.formatIntMoney(printerData.getPointCoverMoney()) + "元", 1, 2));
                    }
                    if (printerData.getCouponCoverMoney() != 0) {
                        jsonArray.put(PrintUtils.setStringContent("优惠券抵扣金额：" + StringUtils.formatIntMoney(printerData.getCouponCoverMoney()) + "元", 1, 2));
                    }
                    if (printerData.getBackAmt() != 0) {
                        jsonArray.put(PrintUtils.setStringContent("返利金额：" + StringUtils.formatIntMoney(printerData.getBackAmt()) + "元", 1, 2));
                    }
                    jsonArray.put(PrintUtils.setfreeLine("2"));
                    break;
                case ConstantsConfig.PAY_WAY_PAY_FLOT:
                case ConstantsConfig.PAY_WAY_RECHARGE_CASH: {
                    jsonArray.put(PrintUtils.setStringContent("收款凭证", 2, 3));
                    jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));// 打印虚线
                    jsonArray.put(PrintUtils.setStringContent("商户名称：" + printerData.getMerchantName(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("终端编号：" + printerData.getTerminalId(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("操作员号：" + printerData.getOperatorNo(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("交易类型：" + "现金/CASH", 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("订 单 号：" + printerData.getClientOrderNo(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("日期时间：" + printerData.getDateTime(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("金 额：RMB " + printerData.getReceiveAmount(), 1, 2));
                    jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));
                    jsonArray.put(PrintUtils.setfreeLine("2"));
                    if (!StringUtils.isBlank(printerData.getRealize_card_num())) {
                        jsonArray.put(PrintUtils.setStringContent("会员卡号：" + StringUtils.formatSTCardNo(printerData.getRealize_card_num()), 1, 2));
                    }
                    if (!StringUtils.isBlank(printerData.getMember_name())) {
                        jsonArray.put(PrintUtils.setStringContent("会员姓名：" + printerData.getMember_name(), 1, 2));
                    }
                    if (!StringUtils.isBlank(printerData.getAmount())) {
                        jsonArray.put(PrintUtils.setStringContent("充值金额：" + printerData.getAmount() + "元", 1, 2));
                    }
                    int largessAmount = StringUtils.stringToInt(printerData.getReceiveAmount()) - StringUtils.stringToInt(printerData.getAmount());
                    if (largessAmount != 0) {
                        jsonArray.put(PrintUtils.setStringContent("充值赠送：" + StringUtils.formatIntMoney(largessAmount) + "元", 1,2));
                    }
                    if (printerData.getOrderAmount() != 0) {
                        jsonArray.put(PrintUtils.setStringContent("到账金额：" + StringUtils.formatIntMoney(printerData.getOrderAmount()) + "元", 1, 2));
                    }
                    if (printerData.getPacektRemian() != 0) {
                        jsonArray.put(PrintUtils.setStringContent("账号余额：" + StringUtils.formatIntMoney(printerData.getPacektRemian()) + "元", 1,2 ));
                    }
                }
                break;
                default:
                    if (printerData.getPointCoverMoney() != 0) {
                        jsonArray.put(PrintUtils.setStringContent("积分抵扣金额：" + StringUtils.formatIntMoney(printerData.getPointCoverMoney()) + "元", 1, 2));
                    }
                    if (printerData.getCouponCoverMoney() != 0) {
                        jsonArray.put(PrintUtils.setStringContent("优惠券抵扣金额：" + StringUtils.formatIntMoney(printerData.getCouponCoverMoney()) + "元",1 ,2 ));
                    }
                    if (printerData.getBackAmt() != 0) {
                        jsonArray.put(PrintUtils.setStringContent("返利金额：" + StringUtils.formatIntMoney(printerData.getBackAmt()) + "元", 1, 2));
                        jsonArray.put(PrintUtils.setfreeLine("2"));
                    }

                    break;

            }


            String printContent = (String) SPUtils.get(context, "printContent", "");
            if (!StringUtils.isBlank(printContent)) {
                jsonArray.put(PrintUtils.setfreeLine("2"));
                jsonArray.put(PrintUtils.setStringContent(printContent, 1, 2));
            }

//            Bitmap bitmap = SPUtils.loadDrawable(context);
//            if (bitmap != null){
//                jsonArray.put(PrintUtils.setbitmap(StringUtils.convertIconToString(bitmap), 2));
//                jsonArray.put(PrintUtils.setfreeLine("2"));
//            }

//            Bitmap pointBitmap = printerData.getPoint_bitmap();
//
//            if (pointBitmap != null) {
//                LogUtils.e("width: " + printerData.getPoint_bitmap().getWidth() + " height: "
//                        + printerData.getPoint_bitmap().getHeight());
//
//                jsonArray.put(PrintUtils.setStringContent("--------------------------------", 1, 2));
//                jsonArray.put(PrintUtils.setStringContent("使用微信扫一扫 获取更多优惠信息", 2, 2));
//                jsonArray.put(PrintUtils.setbitmap(StringUtils.convertIconToString(pointBitmap), 2));
//            }

            if (printerData.getPoint() > 0) {
                jsonArray.put(PrintUtils.setStringContent("本次获得积分：" + printerData.getPoint(), 1, 2));
            }
            if (printerData.getPointCurrent() > 0) {
                jsonArray.put(PrintUtils.setStringContent("积分余额：" + printerData.getPointCurrent(), 1, 2));
            }

            if (!StringUtils.isBlank(printerData.getCouponData())) {
//                    printerDevice.printlnText(format, "--------------------------------");
//                    printerDevice.printlnText(format, "本次消费获得：");
                Gson gson = new Gson();
                List<Couponsn> couponsns = gson.fromJson(printerData.getCouponData(), new TypeToken<List<Couponsn>>() {
                }.getType());
                for (int i=0; i < couponsns.size(); i++){
                    if (couponsns.get(i).getCoupon_type() == 2){
                        jsonArray.put(PrintUtils.setStringContent("折扣券名称：" + couponsns.get(i).getCoupon_name(), 1, 2));
                        jsonArray.put(PrintUtils.setStringContent("折扣券折扣：" + couponsns.get(i).getCoupon_money()/100+"折", 1, 2));
                    }else {
                        jsonArray.put(PrintUtils.setStringContent("优惠券名称：" + couponsns.get(i).getCoupon_name(),1 ,2 ));
                        jsonArray.put(PrintUtils.setStringContent("优惠券金额：" + StringUtils.formatIntMoney(couponsns.get(i).getCoupon_money()), 1, 2));
                    }
                }
            }

            jsonObject.put("spos", jsonArray);
            if (jsonArray.length() > 0){
                return jsonObject.toString();
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }




    /**
     * 打印文本
     */
    public static String  printShiftRoom(final ShiftRoom printerData, final long start_time, final long end_time, final int type) {


        JSONObject jsonObject = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        try {

            if (type == 1) {
                jsonArray.put(PrintUtils.setStringContent("班接统计", 2, 3));
            }else{
                jsonArray.put(PrintUtils.setStringContent("当日统计", 2, 3));
            }
            jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));// 打印虚线
            jsonArray.put(PrintUtils.setStringContent("起始时间："+ StringUtils.timeStamp2Date1(start_time + "")+":00", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("结束时间："+ StringUtils.timeStamp2Date1(end_time + "")+":00", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));// 打印虚线
            jsonArray.put(PrintUtils.setStringContent("刷卡：", 1,2));
            jsonArray.put(PrintUtils.setStringContent("交易笔数："+ ((printerData.getPay_swipe() != null) ? printerData.getPay_swipe().getTrade_num() : "0")+"笔", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("实收金额："+ ((printerData.getPay_swipe() != null) ? StringUtils.formatIntMoney(printerData.getPay_swipe().getReal_pay_money()) : "0")+"元",1, 2));
            jsonArray.put(PrintUtils.setStringContent("优惠券抵扣金额："+ ((printerData.getPay_swipe() != null) ? StringUtils.formatIntMoney(printerData.getPay_swipe().getCoupon_deduct()) : "0")+"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("积分抵扣金额："+ ((printerData.getPay_swipe() != null) ? StringUtils.formatIntMoney(printerData.getPay_swipe().getIntergral_deduct()) : "0")+"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));// 打印虚线
            jsonArray.put(PrintUtils.setStringContent("现金：", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("交易笔数："+ ((printerData.getPay_cash() != null) ? printerData.getPay_cash().getTrade_num() : "0")+"笔", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("实收金额："+ ((printerData.getPay_cash() != null) ? StringUtils.formatIntMoney(printerData.getPay_cash().getReal_pay_money()) : "0") +"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("优惠券抵扣金额："+ ((printerData.getPay_cash() != null) ? StringUtils.formatIntMoney(printerData.getPay_cash().getCoupon_deduct()) : "0")+"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("积分抵扣金额："+ ((printerData.getPay_cash() != null) ? StringUtils.formatIntMoney(printerData.getPay_cash().getIntergral_deduct())  : "0")+"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));// 打印虚线
            jsonArray.put(PrintUtils.setStringContent("微信：", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("交易笔数："+ ((printerData.getPay_wx() != null) ? printerData.getPay_wx().getTrade_num() : "0")+"笔", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("实收金额："+ ((printerData.getPay_wx() != null) ? StringUtils.formatIntMoney(printerData.getPay_wx().getReal_pay_money()) : "0") +"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("优惠券抵扣金额："+ ((printerData.getPay_wx() != null) ? StringUtils.formatIntMoney(printerData.getPay_wx().getCoupon_deduct()) : "0")+"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("积分抵扣金额："+ ((printerData.getPay_wx() != null) ? StringUtils.formatIntMoney(printerData.getPay_wx().getIntergral_deduct())  : "0")+"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));// 打印虚线
            jsonArray.put(PrintUtils.setStringContent("支付宝：", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("交易笔数："+ ((printerData.getPay_aly() != null) ? printerData.getPay_aly().getTrade_num() : "0")+"笔", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("实收金额："+ ((printerData.getPay_aly() != null) ? StringUtils.formatIntMoney(printerData.getPay_aly().getReal_pay_money()) : "0") +"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("优惠券抵扣金额："+ ((printerData.getPay_aly() != null) ? StringUtils.formatIntMoney(printerData.getPay_aly().getCoupon_deduct()) : "0")+"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("积分抵扣金额："+ ((printerData.getPay_aly() != null) ? StringUtils.formatIntMoney(printerData.getPay_aly().getIntergral_deduct())  : "0")+"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));// 打印虚线
            jsonArray.put(PrintUtils.setStringContent("钱包：", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("交易笔数："+ ((printerData.getPay_qb() != null) ? printerData.getPay_qb().getTrade_num() : "0")+"笔", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("实收金额："+ ((printerData.getPay_qb() != null) ? StringUtils.formatIntMoney(printerData.getPay_qb().getReal_pay_money()) : "0") +"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("优惠券抵扣金额："+ ((printerData.getPay_qb() != null) ? StringUtils.formatIntMoney(printerData.getPay_qb().getCoupon_deduct()) : "0")+"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("积分抵扣金额："+ ((printerData.getPay_qb() != null) ? StringUtils.formatIntMoney(printerData.getPay_qb().getIntergral_deduct())  : "0")+"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));// 打印虚线
            jsonArray.put(PrintUtils.setStringContent("刷卡撤销：", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("交易笔数："+ ((printerData.getPay_unswipe() != null) ? printerData.getPay_unswipe().getTrade_num() : "0")+"笔", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("撤销金额："+ ((printerData.getPay_unswipe() != null) ? StringUtils.formatIntMoney(printerData.getPay_unswipe().getReal_undo_money()) : "0") +"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));// 打印虚线
            jsonArray.put(PrintUtils.setStringContent("微信撤销：", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("交易笔数："+ ((printerData.getPay_unwx() != null) ? printerData.getPay_unwx().getTrade_num() : "0")+"笔", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("撤销金额："+ ((printerData.getPay_unwx() != null) ? StringUtils.formatIntMoney(printerData.getPay_unwx().getReal_undo_money()) : "0") +"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));// 打印虚线
            jsonArray.put(PrintUtils.setStringContent("支付宝撤销：", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("交易笔数："+ ((printerData.getPay_unaly() != null) ? printerData.getPay_unaly().getTrade_num() : "0")+"笔", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("撤销金额："+ ((printerData.getPay_unaly() != null) ? StringUtils.formatIntMoney(printerData.getPay_unaly().getReal_undo_money()) : "0") +"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));// 打印虚线
            jsonArray.put(PrintUtils.setStringContent("钱包撤销：", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("交易笔数："+ ((printerData.getPay_unqb() != null) ? printerData.getPay_unqb().getTrade_num() : "0")+"笔", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("撤销金额："+ ((printerData.getPay_unqb() != null) ? StringUtils.formatIntMoney(printerData.getPay_unqb().getReal_undo_money()) : "0") +"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("------------------------------", 1, 2));// 打印虚线
            jsonArray.put(PrintUtils.setStringContent("交易统计：", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("交易总笔数："+ ((printerData.getTotal() != null) ? printerData.getTotal().getTrade_num() : "0")+"笔", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("实收总金额："+ ((printerData.getTotal() != null) ? StringUtils.formatIntMoney(printerData.getTotal().getReal_pay_money()) : "0")+"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("交易撤销总金额："+ ((printerData.getTotal() != null) ? StringUtils.formatIntMoney(printerData.getTotal().getReal_undo_money()) : "0")+"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("优惠券抵扣总金额："+ ((printerData.getTotal() != null) ? StringUtils.formatIntMoney(printerData.getTotal().getCoupon_deduct()) : "0")+"元", 1, 2));
            jsonArray.put(PrintUtils.setStringContent("积分抵扣总金额："+ ((printerData.getTotal() != null) ? StringUtils.formatIntMoney(printerData.getTotal().getIntergral_deduct()) : "0") +"元", 1, 2));
            jsonArray.put(PrintUtils.setfreeLine("4"));





            jsonObject.put("spos", jsonArray);
            if (jsonArray.length() > 0){
                return jsonObject.toString();
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }




}
